<?php
	class GP_page_liste extends GP_controleur
	{
		var $controleur;
		var $table;
		var $action_form;
		
		function __construct()
		{
			global $page;
			$this -> controleur = parent::getInstance($page);
		}
		
		function habilitation_export()
		{
			$hab = array(
				1,
				2
			);
			
			if (in_array(get_s('bo_user_role'), $hab))
				return true;
			return false;
		}
		
		function export($table, $type)
		{
			global $gp_db;
			if ($this -> habilitation_export())
			{
				$requete = get_s('export_' . $table);
				
				$res = $gp_db -> fetchArray($requete);
				if ($type == 'xls')
					make_excel($res, $table);
				else if ($type == 'pdf')
					make_pdf($res, $table);
			}
		}
		
		function grid()
		{
			include_once(DIR_SCRIPTS . 'liste_' . $this -> table . '.php');
		}
		
		function afficher()
		{			
			global $page, $urirw;
			if (strlen($urirw))
			{
				$pagerw = fakeurl($urirw);
				$htmltmp = $this -> controleur -> htmlrw('header');
				$htmltmp .= $this -> controleur -> htmlrw($page);
				$htmltmp .= $this -> controleur -> htmlrw('footer');
				savefile($pagerw, $htmltmp);
				if (!IS_IE)
					header("HTTP/1.1 301 Moved Permanently");
				include($urirw);
			}
			else
			{
				$this -> controleur -> add_html('header');
				$this -> controleur -> add_html($page);
				$this -> controleur -> add_html('footer');
			}
		}
		
		function setvar($var, $val)
		{
			global $urirw;
			if (strlen($urirw))
				$this -> $var = $val;
			else
				$this -> controleur -> $var = $val;
		}
	}
	$gp_fonc = GP_fonctions::getInstance();
	$gp_db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
	$gp_request = GP_secure::getInstance();
	
	$page_liste = new GP_page_liste;
	$erreur_table = false;
	$table = $gp_request -> Get('table', $GLOBALS["table"]);
	$export_bo = $gp_request -> Get('export', $GLOBALS["export_bo"]);
	$type_export_bo = $gp_request -> Get('type_export_bo', $GLOBALS["type_export_bo"]);
	
	if ($export_bo == 1 && strlen($type_export_bo))
		$page_liste -> export($table, $type_export_bo);
	
	if (!strlen($table) || !is_file(DIR_SCRIPTS . 'liste_' . $table . '.php'))
		$erreur_table = true;
	else
	{
		$page_liste -> table = $table;
		$page_liste -> grid();
	}
	
	$page_liste -> setvar('erreur_table', $erreur_table);
	$page_liste -> setvar('table', $table);
	$page_liste -> setvar('page', $GLOBALS["page"]);
	$page_liste -> afficher();
?>